Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macOS): Replace core-graphics to prevent private api usage #165

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

XMLHexagram
Copy link
Collaborator

@XMLHexagram XMLHexagram commented Dec 3, 2024

Summary by Sourcery

New Features:

  • Introduce a custom implementation of core-graphics to replace the existing dependency, preventing the use of private APIs.

Copy link

sourcery-ai bot commented Dec 3, 2024

Reviewer's Guide by Sourcery

This PR replaces the core-graphics crate with a local copy to prevent private API usage on macOS. The implementation copies the entire core-graphics crate into the project and patches it to use the local version instead of the crates.io version.

Class diagram for the new core-graphics implementation

classDiagram
    class CGEvent {
        +type_id() CFTypeID
        +new(source: CGEventSource) Result<CGEvent, ()>
        +new_keyboard_event(source: CGEventSource, keycode: CGKeyCode, keydown: bool) Result<CGEvent, ()>
        +new_mouse_event(source: CGEventSource, mouse_type: CGEventType, mouse_cursor_position: CGPoint, mouse_button: CGMouseButton) Result<CGEvent, ()>
        +post(tap_location: CGEventTapLocation)
        +location() CGPoint
        +set_flags(flags: CGEventFlags)
        +get_flags() CGEventFlags
        +set_type(event_type: CGEventType)
        +get_type() CGEventType
        +set_string(string: &str)
        +get_integer_value_field(field: CGEventField) i64
        +set_integer_value_field(field: CGEventField, value: i64)
        +get_double_value_field(field: CGEventField) f64
        +set_double_value_field(field: CGEventField, value: f64)
    }

    class CGContext {
        +type_id() CFTypeID
        +create_bitmap_context(data: Option<*mut c_void>, width: size_t, height: size_t, bits_per_component: size_t, bytes_per_row: size_t, space: &CGColorSpace, bitmap_info: u32) CGContext
        +data() &mut [u8]
    }

    class CGDisplay {
        +new(id: CGDirectDisplayID) CGDisplay
        +main() CGDisplay
        +null_display() CGDisplay
        +bounds() CGRect
        +display_mode() Option<CGDisplayMode>
        +begin_configuration() Result<CGDisplayConfigRef, CGError>
        +cancel_configuration(config_ref: &CGDisplayConfigRef) Result<(), CGError>
        +complete_configuration(config_ref: &CGDisplayConfigRef, option: CGConfigureOption) Result<(), CGError>
        +configure_display_with_display_mode(config_ref: &CGDisplayConfigRef, display_mode: &CGDisplayMode) Result<(), CGError>
        +configure_display_origin(config_ref: &CGDisplayConfigRef, x: i32, y: i32) Result<(), CGError>
        +configure_display_mirror_of_display(config_ref: &CGDisplayConfigRef, master: &CGDisplay) Result<(), CGError>
        +image() Option<CGImage>
        +screenshot(bounds: CGRect, list_option: CGWindowListOption, window_id: CGWindowID, image_option: CGWindowImageOption) Option<CGImage>
        +screenshot_from_windows(bounds: CGRect, windows: CFArray, image_option: CGWindowImageOption) Option<CGImage>
        +window_list_info(option: CGWindowListOption, relative_to_window: Option<CGWindowID>) Option<CFArray>
        +is_active() bool
        +is_always_in_mirror_set() bool
        +is_asleep() bool
        +is_builtin() bool
        +is_in_hw_mirror_set() bool
        +is_in_mirror_set() bool
        +is_main() bool
        +is_online() bool
        +uses_open_gl_acceleration() bool
        +is_stereo() bool
        +mirrors_display() CGDirectDisplayID
        +primary_display() CGDirectDisplayID
        +rotation() f64
        +screen_size() CGSize
        +serial_number() u32
        +unit_number() u32
        +vendor_number() u32
        +model_number() u32
        +pixels_high() u64
        +pixels_wide() u64
        +active_displays() Result<Vec<CGDirectDisplayID>, CGError>
        +active_display_count() Result<u32, CGError>
        +hide_cursor() Result<(), CGError>
        +show_cursor() Result<(), CGError>
        +move_cursor_to_point(point: CGPoint) Result<(), CGError>
        +warp_mouse_cursor_position(point: CGPoint) Result<(), CGError>
        +associate_mouse_and_mouse_cursor_position(connected: bool) Result<(), CGError>
    }

    class CGFont {
        +type_id() CFTypeID
        +from_data_provider(provider: CGDataProvider) Result<CGFont, ()>
        +from_name(name: &CFString) Result<CGFont, ()>
        +create_copy_from_variations(vars: &CFDictionary<CFString, CFNumber>) Result<CGFont, ()>
        +postscript_name() CFString
        +get_glyph_b_boxes(glyphs: &[CGGlyph], bboxes: &mut [CGRect]) bool
        +get_glyph_advances(glyphs: &[CGGlyph], advances: &mut [c_int]) bool
        +get_units_per_em() c_int
        +copy_table_tags() CFArray<u32>
        +copy_table_for_tag(tag: u32) Option<CFData>
        +copy_variations() Option<CFDictionary<CFString, CFNumber>>
        +copy_variation_axes() Option<CFArray<CFDictionary<CFString, CFType>>>
    }

    class CGImage {
        +new(width: size_t, height: size_t, bits_per_component: size_t, bits_per_pixel: size_t, bytes_per_row: size_t, colorspace: &CGColorSpace, bitmap_info: u32, provider: &CGDataProvider, should_interpolate: bool, rendering_intent: u32) Self
        +type_id() CFTypeID
    }

    class CGDataProvider {
        +type_id() CFTypeID
        +from_buffer<T: AsRef<[u8]> + Sync + Send>(buffer: Arc<T>) Self
        +from_slice(buffer: &[u8]) Self
        +from_custom_data(custom_data: Box<Box<dyn CustomData>>) Self
    }

    class CGPath {
        +from_rect(rect: CGRect, transform: Option<&CGAffineTransform>) CGPath
        +type_id() CFTypeID
        +apply<'a, F>(&'a self, mut closure: &'a F) where F: FnMut(CGPathElementRef<'a>)
    }

    class CGColorSpace {
        +type_id() CFTypeID
        +create_with_name(name: CFStringRef) Option<CGColorSpace>
        +create_device_rgb() CGColorSpace
        +create_device_gray() CGColorSpace
    }
Loading

File-Level Changes

Change Details Files
Add local copy of core-graphics crate
  • Copy all source files from core-graphics crate
  • Include core modules like base, color, context, display, event, font, etc.
  • Maintain original file structure and implementations
  • Copy over cargo manifest, readme and license files
core-graphics/src/base.rs
core-graphics/src/color.rs
core-graphics/src/context.rs
core-graphics/src/data_provider.rs
core-graphics/src/display.rs
core-graphics/src/event.rs
core-graphics/src/event_source.rs
core-graphics/src/font.rs
core-graphics/src/geometry.rs
core-graphics/src/gradient.rs
core-graphics/src/image.rs
core-graphics/src/lib.rs
core-graphics/src/path.rs
core-graphics/src/private.rs
core-graphics/src/sys.rs
core-graphics/src/window.rs
core-graphics/Cargo.toml
core-graphics/README.md
Configure workspace to use local core-graphics
  • Add patch configuration to use local core-graphics instead of crates.io version
Cargo.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @XMLHexagram - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

core-graphics/src/event.rs Show resolved Hide resolved
@Losses Losses merged commit ec19325 into master Dec 3, 2024
2 of 4 checks passed
@XMLHexagram XMLHexagram deleted the fix-app-store branch December 7, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants